package com.xinpu.controller;

import com.xinpu.entity.TBack;
import com.xinpu.service.BackCompanyService;
import com.xinpu.service.ITBackService;
import com.xinpu.service.OwnService;
import com.xinpu.vo.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/back")
public class BackController {
    @Resource
    private ITBackService itBackService;

    @Resource
    private BackCompanyService backCompanyService;

    /**
     * 名片背景列表
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseMessage list() {
        return ResponseMessage.ok(backCompanyService.getList(OwnService.getLoginer().getTenantId()));
    }

    /**
     * 添加  修改  名片背景
     *
     * @param map
     * @return
     */

    @PostMapping("/saveOrUpdate")
    public ResponseMessage saveOrUpdate(@RequestBody Map<String, String> map) {
        TBack tBack = new TBack();
        if (map.get("id") != null) {
            tBack.setId(new Integer(map.get("id")));
        }
        tBack.setImg(map.get("imgOne"));
        tBack.setName(map.get("name"));
        tBack.setSid(0);
        itBackService.saveOrUpdate(tBack);
        return ResponseMessage.ok();
    }

    /**
     * 删除名片背景
     *
     * @param map
     * @return
     */
    @PostMapping("/remove")
    public ResponseMessage remove(@RequestBody Map<String, Integer> map) {
        return ResponseMessage.ok(itBackService.removeById(map.get("id")));
    }
}
